package com.kx.smartdevice.mapper;

import com.kx.smartdevice.pojo.Device;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName DevicesMapper
 * @Author Sun
 * @Date 2021/6/1 14:21
 */

public interface DeviceMapper {

    List<Device> getAllDevices(@Param("address") String address,@Param("status") Integer status,@Param("direction") int direction,@Param("areaid") int areaid,@Param("categoryid") int categoryid);

    @Insert("INSERT INTO devices (devicesuuid,devicename,address,areaid,direction,num,status,categoryid) VALUES(#{devicesuuid},#{devicename},#{address},#{areaid},#{direction},#{num},#{status},#{categoryid})")
    void AddDevice(Device device);

    void deleteDevices(@Param("ids") String[] ids);

    void updateDevice(Device device);

    @Select("SELECT d.* , a.areaname areaname, c.categoryname categoryname FROM devices d  join areas a   join categories c on d.areaid =a.id and d.categoryid= c.id WHERE d.id = #{id}")
    Device getDeviceById(Long id);

    @Select("SELECT categoryid FROM devices WHERE devicesuuid=#{uuid}")
    Long getCategoryIdByUUID(String uuid);

    @Update("UPDATE devices SET  status =#{status}  WHERE devicesuuid = #{uuid}")
    void updateoffLine(@Param("uuid") String uuid,@Param("status") String status);
}
